<template>
  <div class="HuikuiInfo el-card is-always-shadow el-card__body">
    <el-dialog
      title="回馈预览"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-crud
        ref="crud"
        :option="optionTable"
        :data="listTable">
        <template slot="menuLeft">
          回馈SC层级系统数据
        </template>
        <template slot-scope="scope" slot="replySaleMoney">
          <el-input-number :disabled="showType!=1" controls-position="right" v-model="formData.replySaleMoney" :precision="2"></el-input-number>
        </template>
        <template slot-scope="scope" slot="replyRechargeMoney">
          <el-input-number :disabled="showType!=1" controls-position="right" v-model="formData.replyRechargeMoney" :precision="2"></el-input-number>
        </template>
        <template slot-scope="scope" slot="replyErrorReturnMoney">
          <el-input-number :disabled="showType!=1" controls-position="right" v-model="formData.replyErrorReturnMoney" :precision="2"></el-input-number>
        </template>
      </avue-crud><br/><br/><br/>
      <avue-form :disabled="isReload" :option="option" v-model="formData" @submit="handleSubmit">
        <template  slot="jdReplyReason" slot-scope="scope">
          <el-select :disabled="showType==2" v-model="jdReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in jdReplyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="kyReplyReason">
          <el-select disabled v-model="formData.kyReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in kyReplyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menuForm" >
          <el-button v-if="showType==1" type="primary" @click="handleSubmit" >确认</el-button>
          <el-button @click="closed" >返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import ExportJsonExcel from "js-export-excel";
  import {
    fenExYuangettoFixed,
    fenExYuangettoFixed2, getStationName,
    getSysDictItemListToDict
  } from "../../../../../api/subwayRat/commonCheck";
  import {updateSwAuConductorToBeChecked} from "../../../../../api/stationTiecketManager/shuJuXieChaGuanLi/BOM/shouPiaoYuanPKCYXC";
  import ElInput from "../../../../../../node_modules/element-ui/packages/input/src/input";
  export default {
    components:{
      ElInput
    },
    data() {
      return {
        jdReplyReason :'',
        replySaleMoney:0,
        replyRechargeMoney:0,
        replyErrorReturnMoney:0,
        optionTable:{},
        listTable:[],
        option:{},
        showType : 0,
        isReload:true,
        dialogVisible:true,
        formData:{
          replySaleMoney:'',
          replyRechargeMoney:'',
          replyErrorReturnMoney:'',
          diffMoney: ''
        },
        jdReplyReasonList:[],
        kyReplyReasonList:[]
      }
    },
    created() {
      this.showType = this.$parent.showType;
      getSysDictItemListToDict({"type":"KY_REPLY_REASON"}).then((response)=>{
        this.kyReplyReasonList = response.data.data;
      });
      getSysDictItemListToDict({"type":"JD_REPLY_REASON"}).then((response)=>{
        this.jdReplyReasonList = response.data.data;
      });
      this.getOption();
    },
    methods: {
      async handleSubmit(){
        if(''==this.jdReplyReason ||this.jdReplyReason==undefined){       
          this.$message.warning("请选择机电专业差异回馈原因！");
          return
        }
	if(this.formData.jdReplyDetail=='' || this.formData.jdReplyDetail==undefined){
	   this.$message.error("请填写机电专业详细描述！");
          return
	}
	if(this.formData.jdReplyDetail.length>500){
	   this.$message.error("字数超过限制，请修改在500字以内！");
           return
	}
        let p = {
          id:this.formData.id,
          jdReplyReason:this.jdReplyReason,
          jdReplyDetail:this.formData.jdReplyDetail,
          replySaleMoney:Number(this.formData.replySaleMoney)*100,
          replyRechargeMoney:Number(this.formData.replyRechargeMoney)*100,
          replyErrorReturnMoney:Number(this.formData.replyErrorReturnMoney)*100,
        };
        await updateSwAuConductorToBeChecked(p).then((response)=>{
          if(response.data.code==0){
            this.$message.success("操作成功");
          }else{
            this.$message.error("操作失败");
          }
        });
        this.$parent.getList();
        this.closed();
      },
      recallShow(row){
        this.jdReplyReason = row.jdReplyReason;
        Object.assign(this.formData,row);
        this.formData.replySaleMoney=fenExYuangettoFixed2(this.formData.replySaleMoney);
        this.formData.replyRechargeMoney=fenExYuangettoFixed2(this.formData.replyRechargeMoney);
        this.formData.replyErrorReturnMoney=fenExYuangettoFixed2(this.formData.replyErrorReturnMoney);
        this.formData.diffMoney=fenExYuangettoFixed2(this.formData.diffMoney);
        this.listTable.push(row);
        if(1==this.showType){
          this.option.group[0].column[8].disabled = false;
        }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        if(1 == this.$parent.showType) {
          this.isReload = false;
        }
        this.optionTable = {
          border: false,
          index: false,
          indexLabel: '序号',
          stripe: false,
          menuAlign: 'center',
          menu: false,
          viewBtn: false,
          editBtn: false,
          emptyBtn:false,
          delBtn: false,
          align: 'center',
          addBtn: false,
          column: [{
            label: '回馈售票金额',
            prop: 'replySaleMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replySaleMoney');
            },
            cell:true,
            slot:true,
            search: false,
            hide: false,
          },{
            label: '回馈充值金额',
            prop: 'replyRechargeMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyRechargeMoney');
            },
            cell:true,
            slot:true,
            search: false,
            hide: false,
          },{
            label: '回馈补票金额',
            prop: 'replyErrorReturnMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyErrorReturnMoney');
            },
            cell:true,
            slot:true,
            search: false,
            hide: false,
          }]
        };
        this.option={
          submitBtn:false,
          emptyBtn:false,
          group:[{
              icon:'',
              label: '',
              // collapse:false,
              prop: 'group',
              column: [
                {
                  type: 'select',
                  label: '站点',
                  prop: 'stationCode',
                  labelWidth:130,
                  props: {
                    label: 'name',
                    value: 'code'
                  },
                  dicFlag: true,
                  disabled:true,
                  dicUrl: `/support/swparamstation/dict/9`,
                },
                {
                label: '售票员',
                prop: 'conductorPersonName',
                disabled:true,
                labelWidth:130
              },{
                label: '工号',
                prop: 'conductorPersonCode',
                disabled:true,
                labelWidth:130
              },{
                label: '收入日期',
                prop: 'recordTime',
                disabled:true,
                labelWidth:130
              },
                {
                  label: '设备操作号',
                  prop: 'equipmentNumber',
                  disabled:true,
                  labelWidth:130
                },
                {
                label: '差异金额',
                prop: 'diffMoney',
                disabled:true,
                labelWidth:130,
                formatter:function (row,value , label, column) {
                  return fenExYuangettoFixed(row,'diffMoney');
                }
              },{
                label: '机电专业回馈差异原因',
                prop: 'jdReplyReason',
                formslot : true,
                labelWidth:130
              },{
                label: '车站回馈差异原因',
                prop: 'kyReplyReason',
                formslot : true,
                labelWidth:130
              },{
                label: '机电专业详细描述',
                prop: 'jdReplyDetail',
                disabled:true,
                type:'textarea',
                labelWidth:130
              },{
                label: '车站回馈详细描述',
                prop: 'kyReplyDetail',
                disabled : true,
                type:'textarea',
                labelWidth:130
              }]
            }]
        }
      }
    },
    mounted() {
    }
  }
</script>
